

SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;


CREATE SCHEMA s_message;


COMMENT ON SCHEMA s_message IS 'Message Admin';


SET search_path = s_message, pg_catalog;

CREATE FUNCTION created_at_function() RETURNS trigger
LANGUAGE plpgsql
AS $$
declare
  t timestamptz;
BEGIN
  t := now();
  NEW.created_at = t;
  NEW.updated_at = t;
  RETURN NEW;
END;
$$;


CREATE FUNCTION updated_at_function() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
  NEW.updated_at = clock_timestamp();
  RETURN NEW;
END;
$$;


SET default_tablespace = '';

SET default_with_oids = false;


CREATE TABLE databasechangelog (
  id character varying(255) NOT NULL,
  author character varying(255) NOT NULL,
  filename character varying(255) NOT NULL,
  dateexecuted timestamp without time zone NOT NULL,
  orderexecuted integer NOT NULL,
  exectype character varying(10) NOT NULL,
  md5sum character varying(35),
  description character varying(255),
  comments character varying(255),
  tag character varying(255),
  liquibase character varying(20),
  contexts character varying(255),
  labels character varying(255),
  deployment_id character varying(10)
);



CREATE TABLE databasechangeloglock (
  id integer NOT NULL,
  locked boolean NOT NULL,
  lockgranted timestamp without time zone,
  lockedby character varying(255)
);

DROP TABLE IF EXISTS "s_message"."t_message";
CREATE TABLE "s_message"."t_message" (
  "id" BIGSERIAL NOT NULL,
  "user_id" int8 NOT NULL,
  "open_id" text COLLATE "pg_catalog"."default" NOT NULL,
  "message" text COLLATE "pg_catalog"."default",
  "title" text COLLATE "pg_catalog"."default",
  "type" int2 NOT NULL,
  "created_at" timestamp(0) NOT NULL,
  "updated_at" timestamp(0) NOT NULL,
  "deleted_at" timestamp(0)
)
;
ALTER TABLE "s_message"."t_message" OWNER TO "postgres";
COMMENT ON COLUMN "s_message"."t_message"."type" IS '1,系统 2,订单';

-- ----------------------------
-- Primary Key structure for table t_message
-- ----------------------------
ALTER TABLE "s_message"."t_message" ADD CONSTRAINT "t_message_pkey" PRIMARY KEY ("id");

CREATE TRIGGER "created_at_user_trigger" BEFORE INSERT ON "s_message"."t_message"
  FOR EACH ROW
EXECUTE PROCEDURE "s_message"."created_at_function"();
CREATE TRIGGER "updated_at_user_trigger" BEFORE INSERT ON "s_message"."t_message"
  FOR EACH ROW
EXECUTE PROCEDURE "s_message"."updated_at_function"();


